﻿Imports Microsoft.VisualBasic
Imports System.Configuration.ConfigurationManager
Imports System.Data
Imports System.Data.SqlClient
Imports System

Public Class ClienteDAO
    'instanciar la conexion
    Dim cn As New SqlConnection(ConnectionStrings("cn").ConnectionString)

    Public Sub Agregar(ByVal cli As ClienteBE)
        cn.Open()
        Try
            'comando de insercion
            Dim cmd As New SqlCommand(
                "Insert into tb_cliente(cod_cliente,password_cliente,email_cliente,nom_cliente,ape_cliente) values(@cod,@pwd,@email,@nom,@ape)", cn) '* 	

            'lista de parametros
            With cmd.Parameters
                .Add("@cod", SqlDbType.VarChar).Value = cli.cod_cliente
                .Add("@pwd", SqlDbType.VarChar).Value = cli.password_cliente
                .Add("@email", SqlDbType.VarChar).Value = cli.email_cliente
                .Add("@nom", SqlDbType.VarChar).Value = cli.nom_cliente '* 		
                .Add("@ape", SqlDbType.VarChar).Value = cli.ape_cliente '*
            End With

            cmd.ExecuteNonQuery() 'ejecutar
        Catch ex As Exception
            'MsgBox("Login ya en uso, por favor ingrese otro")
            MsgBox(ex.Message) 'mensaje en caso error
        Finally
            cn.Close() 'al finalizar cerrar la conexion
        End Try
    End Sub

    Public Sub Actualizar(ByVal cli As ClienteBE)
        cn.Open()
        Try
            'comando de insercion
            Dim cmd As New SqlCommand(
                "Update tb_cliente set email_cliente=@email,password_cliente=@pwd,nom_cliente=@no,ape_cliente=@ap,direc_cliente=@di,tfno_cliente=@tf,tipo_doc=@ti,nro_doc=@nu where cod_cliente=@cod ", cn)

            'lista de parametros
            With cmd.Parameters
                .Add("@cod", SqlDbType.VarChar).Value = cli.cod_cliente
                .Add("@pwd", SqlDbType.VarChar).Value = cli.password_cliente
                .Add("@email", SqlDbType.VarChar).Value = cli.email_cliente
                .Add("@no", SqlDbType.VarChar).Value = cli.nom_cliente
                .Add("@ap", SqlDbType.VarChar).Value = cli.ape_cliente
                .Add("@di", SqlDbType.VarChar).Value = cli.direc_cliente
                .Add("@tf", SqlDbType.VarChar).Value = cli.tfno_cliente
                .Add("@ti", SqlDbType.VarChar).Value = cli.tipo_doc
                .Add("@nu", SqlDbType.VarChar).Value = cli.nro_doc
            End With

            cmd.ExecuteNonQuery() 'ejecutar
        Catch ex As Exception
            MsgBox(ex.Message) 'mensaje en caso error
        Finally
            cn.Close() 'al finalizar cerrar la conexion
        End Try
    End Sub







End Class
